package org.flexlancer.databases
{
	public class Person
	{
		public static const TABLE:String = "person";
/*
this.CreateTable("person",
									["id INTEGER PRIMARY KEY AUTOINCREMENT",
									"refid INTEGER DEFAULT 0",
									"name TEXT",
									"cnic TEXT",
									"phone TEXT",
									"address TEXT"]);
*/
		public static function Add(refID:Number,personname:String, persontypeid:Number,cnic:String,phone:String,address:String):void{
			try{
				var insertObj:Object = new Object();
				insertObj.refid = refID;
				insertObj.typeid = persontypeid;
				insertObj.name = personname;
				insertObj.cnic = cnic;
				insertObj.phone = phone;
				insertObj.address = address;
				DatabaseManager.Manager.Insert(TABLE,insertObj);
			}catch(err:Error){
				throw err;
			}
		}

		public static function Update(personid:Number, refID:Number,personname:String ,persontypeid:Number,cnic:String,phone:String,address:String):void{
			try{
				var updateObj:Object = new Object();
				updateObj.refid = refID;
				updateObj.typeid = persontypeid;
				updateObj.name = personname;
				updateObj.cnic = cnic;
				updateObj.phone = phone;
				updateObj.address = address;
				DatabaseManager.Manager.Update(TABLE,updateObj,"id = "+personid);
			}catch(err:Error){
				throw err;
			}
		}

		public static function List(condition:String = ""):Array{
			try{
				return DatabaseManager.Manager.Select(TABLE,null,condition,"name"); 
			}catch(err:Error){
				throw err;
			}
			return new Array;
		}
		public static function Delete(condition:String = ""):void{
			try{
				DatabaseManager.Manager.Delete(TABLE,condition);
			}catch(err:Error){
				throw err;
			}
		}		
	}
}